package dev.android.yeqh.tvannounce;

import java.util.List;
import dev.android.yeqh.tvannounce.adapters.ProgramAdapter;
import dev.android.yeqh.tvannounce.common.Constants;
import dev.android.yeqh.tvannounce.common.NetTask;
import dev.android.yeqh.tvannounce.common.Utils;
import dev.android.yeqh.tvannounce.model.NetTaskParam;
import dev.android.yeqh.tvannounce.model.Program;
import android.os.Bundle;
import android.widget.ListView;

public class ProgramActivity extends BaseActivity {
	ListView lvPrograms = null;
	ProgramAdapter adapter = null;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.program_list);
        
        lvPrograms = (ListView)findViewById(R.id.program_list_list);
        
        try {
        	new NetTask(this).execute(new NetTaskParam(Constants.NET_TASK_GET_PROGRAMS, 
        			getIntent().getStringExtra("channel_id")));
        	adapter = new ProgramAdapter(null, this, R.layout.item_program);

        	lvPrograms.setAdapter(adapter);
        } catch (Exception e) {
			Utils.showMessage(this, e);
		}
    }
    
    @SuppressWarnings("unchecked")
	@Override
    public void updateUI(Object result) {
    	try {
	    	adapter.setPrograms((List<Program>)result);
	    	adapter.notifyDataSetChanged();
    	} catch (Exception e) {
    		Utils.showMessage(this, e);
		}
    }
}